﻿Imports System.Data.SqlClient
Imports System.Configuration
Imports DLLDungChung
Imports clslaycauhinhmay

Module MD
    Public dangnhap As String = ""
    Public conn As New SqlConnection(ConfigurationManager.AppSettings("strconn"))
    Public giatri2 As String = ""
    Public thoigianfree As DateTime
    Public masokey As String = ""
    Public cauhinhmaytinh = MaHoaDuLieu.giaima(My.Computer.Registry.GetValue(
"HKEY_CURRENT_USER\Software\AppStore", "cauhinhmay", Nothing))
    Function test(ByVal sql As String, ByVal ct As CommandType, ByVal ParamArray param() As SqlParameter) As Boolean
        If conn.State = ConnectionState.Open Then
            conn.Close()
        End If
        conn.Open()
        Try
            Dim cmd As New SqlCommand(sql, conn)
            cmd.CommandType = ct
            cmd.Parameters.Clear()
            If IsDBNull(param) Then

            Else
                For Each b As SqlParameter In param
                    cmd.Parameters.Add(b)
                Next

            End If
            cmd.ExecuteNonQuery()
            Return True
        Catch ex As Exception
            Return False
        Finally
            conn.Close()
        End Try


    End Function



    Function laykey(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer, ByVal q As Integer, ByVal w As Integer, ByVal e As Integer, ByVal r As Integer) As String
        Dim s As String = CauHinhMay.FindMACAddress + CauHinhMay.GetCPUId
        Dim kq = s.Substring(0, 4) + "-" + s.Substring(5, 4) + "-" + s.Substring(9, 4) + "-" + s.Substring(13, 4) + "-" + s.Substring(17, 4) + "-" + s.Substring(21, 4) + "-" + s.Substring(25, 3)
        Dim mang() As String = kq.Split("-")
        Return mang(x) + "-" + mang(y) + "-" + mang(z) + "-" + mang(q) + "-" + mang(w) + "-" + mang(e) + "-" + mang(r)
    End Function
    Sub laycauhinhmaypro()
        Dim rand = New Random
        Dim x As Integer = rand.Next(0, 6)
        Dim y As Integer = rand.Next(0, 6)
        Dim z As Integer = rand.Next(0, 6)
        Dim q As Integer = rand.Next(0, 6)
        Dim w As Integer = rand.Next(0, 6)
        Dim e As Integer = rand.Next(0, 6)
        Dim r As Integer = rand.Next(0, 6)



        giatri2 = laykey(x, y, z, q, w, e, r)




        My.Computer.Registry.SetValue(
            "HKEY_CURRENT_USER\Software\AppStore", "cauhinhmaypro", giatri2 + masokey)
    End Sub
    Sub laycauhinhmay()

        Dim x As Integer = 0
        Dim y As Integer = 1
        Dim z As Integer = 2
        Dim q As Integer = 3
        Dim w As Integer = 4
        Dim e As Integer = 5
        Dim r As Integer = 6

        giatri2 = MaHoaDuLieu.mahoa(laykey(x, y, z, q, w, e, r))

        My.Computer.Registry.SetValue(
            "HKEY_CURRENT_USER\Software\AppStore", "cauhinhmay", (giatri2))
    End Sub
    Sub dkdungthu()
        Dim thoigiancon As DateTime = Date.Now
        thoigianfree = thoigiancon.AddDays(30)
        My.Computer.Registry.SetValue(
           "HKEY_CURRENT_USER\Software\AppStore", "thoigianfree", MaHoaDuLieu.mahoa((thoigianfree.ToString("dd-MM-yyyy"))))
        MsgBox("đã đăng ký dùng thử")
    End Sub
End Module
